{{template "base.html" .}}

{{define "content"}}


<div style="padding: 5% 10%;padding-bottom: 0">
<!--操作按钮模板-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!--操作按钮模板end-->
<div class="layui-btn-group demoTable">
    <button class="layui-btn" id="getadd">添加</button>
</div>
    <table id="table-product" lay-filter="demo"></table>
</div>
<style>
    .layui-table-cell{
        height: 100%;
    }
    .layui-table-cell img {
        height: 100%;
        width: 100%;
    }

</style>
<script>
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#table-product'
            ,url: 'http://127.0.0.1:8080/teacher/CarouselList' //数据接口
            ,limit: 15
            ,height: 'full-300'
            ,cols: [[ //表头，下面为表中个字段
                {field: 'Id', title: '编号',  sort: true, align:'center'}
                ,{field: 'Title', title: '标题',  align:'center'}
                ,{field: 'Context', title: '描述',  sort: true, align:'center'}
                ,{field: 'Url', title: '图片',  align:'center', templet:function (d) {
                        return '<img src='+d.Url+'>'}}
                ,{field: 'Link', title: '链接',  sort: true, align:'center'}
                ,{field: 'StringTime', title: '创建时间',  align:'center'}
                ,{field: 'right', title: '操作',templet:'#barDemo', width: 130, align:'center'}
            ]]
        });
    });

    layui.use('table', function(){
        var table = layui.table;
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定删除该轮播图吗', function(index){
                    $.ajax({
                        url:'/teacher/Carousel/del/'+data.Id,
                        method:'DELETE',
                        data:data.field,
                        dataType:'JSON',
                        success:function(res){
                            if(res.code=='0'){
                                layer.msg("删除成功",{icon: 1, time: 1000},function(){}); //提交成功后刷新页面
                                obj.del();
                            }
                            else
                                layer.msg("删除失败",{icon: 1, time: 1000},function(){}); //提交成功后刷新页面
                        },
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    title: '添加轮播图',
                    maxmin: true,
                    skin: 'layui-layer-lan',
                    shadeClose: true, //点击遮罩关闭层
                    area : ['700px' , '600px'],
                    content:'/teacher/Carousel/get/'+data.Id//弹框显示的url,对应的页面
                });
            } else if(obj.event === 'testRecord'){
                location.href="/teacher/stu_test/record/"+data.Id
            }
        });

        $("#getadd").on('click', function(){
            layer.open({
                type: 2,
                title: '添加轮播图',
                maxmin: true,
                skin: 'layui-layer-lan',
                shadeClose: true, //点击遮罩关闭层
                area : ['700px' , '600px'],
                content:'/teacher/Carousel/add'//弹框显示的url,对应的页面
            });
        });
    });




</script>



{{end}}



